*******************************************************************************
*****************************  Figure A4  *************************************
******  Tracing the source of disempowerment: Votes per man/woman,  ***********
*********  by sources and across condition, separately by study  **************
************  by sex of vote grantor and across conditions  *******************
*******************************************************************************

clear all
set more off

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_a4"

*******************************************************************************

use "figure_a4_dataset.dta", replace

collapse (mean) *val *exp, by(female condition_maj_min study)
reshape long @_val @_exp, i(female condition study) j(variable) string
g mean = .
g sd = .
g N = .
g group_N = .
g pXexp = .

forval i = 1/`c(N)' {
//local i = 1
local f = female[`i']
local c = condition_maj_min[`i']
local v = variable[`i']
local exp = _exp[`i']
local study = study[`i']

preserve
use "figure_a4_dataset.dta", clear
sum `v'_val if female == `f' & condition_maj_min==`c' & study == `study', d
local xbar = `r(mean)'
local sd = `r(sd)'
local N = `r(N)'
ttest `v'_val = `exp' if female == `f' & condition_maj_min==`c'  & study == `study'
local pXexp = `r(p)'
distinct studyXgroup if female == `f' & condition_maj_min==`c'  & study == `study'
local group_N = `r(ndistinct)'
restore

replace mean = `xbar' if _n==`i'
replace sd = `sd' if _n==`i'
replace N = `N' if _n==`i'
replace pXexp = `pXexp' if _n==`i'
replace group_N = `group_N' if _n==`i'

}


g meanse = sd/sqrt(N)
g clustermeanse = sd/sqrt(group_N)
g tIID = (_val-_exp)/meanse
g tcluster = (_val-_exp)/ clustermeanse
g ci =  clustermeanse*1.96
g sex = cond(female==1, "Women", "Men")
g pval_cluster = (2 * ttail(group_N-1, abs((_val-_exp)/clustermeanse)))


export delimited using "figure_a4_input.csv", delim(",") replace
